<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    protected $table = 'v_orders';

    /**
     * 不可批量赋值的属性
     * @var array
     */
    protected $guarded = ['id'];

    // 订单状态
    const STATUS_PUBLISH = 10;
    const STATUS_FINISH = 20;
    const STATUS_CANCEL = 30;

    // 损耗扣款
    const LOSS_DEDUCT_N = -1; // 不扣款
    const LOSS_DEDUCT_Y = 1; // 扣款

    // 状态描述
    public static $statusDesc = [
        self::STATUS_PUBLISH => '已发布',
        self::STATUS_FINISH => '已完成',
        self::STATUS_CANCEL => '已取消',
    ];

    // 单位说明
    public static $unit = [
        1 => '元/吨',
        2 => '元/件',
        3 => '元/个',
        4 => '元/趟',
    ];

    // 货运记录
    public function shipping()
    {
        return $this->hasMany('App\Models\Shipping', 'order_id', 'id');
    }

    // 线路信息
    public function route()
    {
        return $this->belongsTo('App\Models\OwnerRoutes', 'route_id', 'id');
    }

    // 车辆方案信息
    public function scheme()
    {
        return $this->belongsTo('App\Models\CarScheme', 'car_scheme_id', 'id');
    }

    // 发货人信息
    public function sender()
    {
        return $this->belongsTo('App\Models\Member', 'sender_uuid', 'uuid');
    }

    // 收货人信息
    public function receiver()
    {
        return $this->belongsTo('App\Models\Member', 'receiver_uuid', 'uuid');
    }
}
